<template>
  <div :class="className" :style="{height:height,width:width}" style="margin-top: -30px;" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'

  const animationDuration = 6000

  export default {
    mixins: [resize],
    props: {
      date_key: {
        type: Array,
        default: []
      },
      date_values: {
        type: Array,
        default: []
      },
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '300px'
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')

        this.chart.setOption({
          xAxis: {
            type: 'category',
            boundaryGap: false,
            data: this.date_key,
          },
          yAxis: {
            type: 'value'
          },
          series: [{
            data: this.date_values,
            type: 'line',
            areaStyle: {}
          }]

        })
      }
    }
  }
</script>
